clear all;
clc;

% ----------------------- Importing Data ----------------------------------

cd('deviation_n20');

volreg = 0;
if(volreg == 1)
    R_epimp = 1;
    R_epibp = 1;
    R_submp = 1;
    R_subbp = 1;
    stimtag = 'Voltage';
    unittag = ' (V)';
else
    R_epimp = 508e-3;
    R_epibp = 422*2*1e-3;
    R_submp = 102e-3;
    R_subbp = 48*2*1e-3;
    stimtag = 'Current';
    unittag = ' (mA)';
end

epi_mp_dc = load('neg_epi_mp_dc_act_100axons_312nodes_9um.txt');
epi_mp_dcbox = zeros(10,10);
epi_mp_dcbox(:) = -epi_mp_dc(:,1);

sub_mp_dc = load('neg_sub_mp_dc_act_100axons_312nodes_9um.txt');
sub_mp_dcbox = zeros(10,10);
sub_mp_dcbox(:) = -sub_mp_dc(:,1);

epi_bp_dc = load('neg_epi_bp_dc_act_100axons_312nodes_9um.txt');
epi_bp_dcbox = zeros(10,10);
epi_bp_dcbox(:) = -epi_bp_dc(:,1);

sub_bp_dc = load('neg_sub_bp_dc_act_100axons_312nodes_9um.txt');
sub_bp_dcbox = zeros(10,10);
sub_bp_dcbox(:) = -sub_bp_dc(:,1);

cd ..;

% ----------------------- Plot Monpolar Case ------------------------------

yf = max(max(cat(2,epi_mp_dcbox/R_epimp,sub_mp_dcbox/R_submp)));

hf2 = figure;
vertlv = {'T12','L1','L2','L3','L4','L5','S1','S2','S3','S4-5'};
subplot(2,1,1),boxplot(epi_mp_dcbox/R_epimp,'labels',vertlv);
title('Monopolar Epidural Stimulation','FontSize',30,'FontWeight','b');
ylabel({['Cathodic ',stimtag];'Stimulation Threshold'},'FontSize',30); 
ylim([0,1.1*yf]);
set(gca,'FontSize',24);
set(gca,'xtick',1:size(epi_mp_dcbox,2),'xticklabel',vertlv,'FontSize',30);

subplot(2,1,2),boxplot(sub_mp_dcbox/R_submp,'labels',vertlv);
title('Monopolar Intradural Stimulation','FontSize',30,'FontWeight','b');
ylabel({['Cathodic ',stimtag];'Stimulation Threshold'},'FontSize',30); 
ylim([0,1.1*yf]);
set(gca,'FontSize',24);
set(gca,'xtick',1:size(epi_mp_dcbox,2),'xticklabel',vertlv,'FontSize',30);

% ----------------------- Plot Bipolar Case -------------------------------

yf = max(max(cat(2,epi_bp_dcbox/R_epibp,sub_bp_dcbox/R_subbp)));
yfp = max(max(sub_bp_dcbox/R_subbp));

figure;
vertlv = {'T12','L1','L2','L3','L4','L5','S1','S2','S3','S4-5'};
subplot(2,1,1),boxplot(epi_bp_dcbox/R_epibp,'labels',vertlv);
title('Bipolar (Proximal Cathode) Epidural Stimulation','FontSize',30,'FontWeight','b');
ylabel({['Cathodic ',stimtag];'Stimulation Threshold'},'FontSize',30); 
ylim([0,1.1*yf]);
set(gca,'FontSize',24);
set(gca,'xtick',1:size(epi_mp_dcbox,2),'xticklabel',vertlv,'FontSize',30);

subplot(2,1,2),boxplot(sub_bp_dcbox/R_subbp,'labels',vertlv);
title('Bipolar (Proximal Cathode) Intradural Stimulation','FontSize',30,'FontWeight','b');
ylabel({['Cathodic ',stimtag];'Stimulation Threshold'},'FontSize',30); 
ylim([0,1.1*yf]);
set(gca,'FontSize',24);
set(gca,'xtick',1:size(epi_mp_dcbox,2),'xticklabel',vertlv,'FontSize',30);

figure;
boxplot(sub_bp_dcbox/R_subbp,'labels',vertlv);
title('Bipolar (Proximal Cathode) Intradural Stimulation','FontSize',30,'FontWeight','b');
ylabel({['Cathodic ',stimtag];['Stimulation Threshold',unittag]},'FontSize',30); 
ylim([0,1.1*yfp]);
set(gca,'FontSize',24);
set(gca,'xtick',1:size(epi_mp_dcbox,2),'xticklabel',vertlv,'FontSize',30);